package control;

import java.util.LinkedList;

public class CommandLine {
	/*
	 * why use static
	 */
	static interface F<X> {
		public void f(X x);
	}
	
	static enum Kind {
		Empty, Bool, Int, String, StringList
	}
	
	static class Arg<X> {
		String name;
		String option;
		String description;
		Kind kind;
		F<X> action;
		
		Arg(String name, String option, String description, Kind kind, F<X> action) {
			this.name = name;
			this.option = option;
			this.description = description;
			this.kind = kind;
			this.action = action;
		}
	}
	
	private LinkedList<Arg<?>> args;
	
	public CommandLine() {
		this.args = new LinkedList<Arg<?>>();
	}
	
	/*
	 * scan the command line arguments
	 */
	public void scan(String args) {
	}
	
	private void outputSpace(int n) {
		if (n < 0) {
			util.Error.bug();
		}
		while(n-- > 0) {
			System.out.print(" ");
		}
	}
	
	private void output() {
		int max = 0;
		
		System.out.println("Available options:");
	    for (Arg<?> a : this.args) {
	      int current = a.name.length();
	      System.out.print("-" + a.name + " ");
	      if (a.option != null) {
	        current += a.option.length();
	        System.out.print(a.option);
	      } else
	        ;
	      outputSpace(max - current + 1);
	      System.out.println(a.description);
	    }
	    return;
	}
	
	public void usage() {
		System.out.println("The Quick Algorithm. Copyright (C) 2014-, qingang.\n"
	            + "Usage: java QuickSort [options] <filename>\n");
		
		output();
	}
}
